package com.credithc.customers.manager.controller;

import com.alibaba.fastjson.JSON;
import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.manager.ro.CustomerModifyRo;
import com.credithc.customers.manager.service.ICustomerModifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zhukai
 * @date 2018/12/17 17:30
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class CustomerModifyController {

    private final MessageFactory messageFactory;

    private final ICustomerModifyService customerModifyService;

    @Autowired
    public CustomerModifyController(MessageFactory messageFactory, ICustomerModifyService customerModifyService) {
        this.messageFactory = messageFactory;
        this.customerModifyService = customerModifyService;
    }

    @PostMapping("/customerModify")
    public Message queryCustomerModifyInfo(@RequestParam(required = false,defaultValue = "1") int page,@RequestParam(required = false,defaultValue = "20") int limit,@RequestParam(required = false) String ro) {
        CustomerModifyRo customerModifyRo = JSON.parseObject(ro, CustomerModifyRo.class);
        customerModifyRo.setPageNo(page);
        customerModifyRo.setPageSize(limit);
        Map<String, PageInfo> map = customerModifyService.getModifyList(customerModifyRo);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }

    @PostMapping("/customerModify/stats")
    public Message statsCustomerModify(@RequestParam(required = false) String type,@RequestParam(required = false) String statsType,@RequestParam(required = false) String dateType){
        Map<String, String> map = customerModifyService.statsModify(type,statsType,dateType);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, map);
    }
}
